package com.ecoolex.chinadutyfree.retailer.api.graphql;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;

import com.ecoolex.chinadutyfree.retailer.entity.GoodsBrand;
import com.ecoolex.chinadutyfree.retailer.ws.GoodsService;
import com.ecoolex.framework.common.pojo.Page;
import com.ecoolex.framework.common.pojo.Pagination;
import com.ecoolex.framework.modularize.api.service.storage.StorageInfo;
import com.ecoolex.framework.modularize.api.service.storage.StorageService;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module;
import com.ecoolex.framework.web.api.graphql2.annotation.QueryField;
import com.ecoolex.framework.web.api.graphql2.annotation.Source;
import com.ecoolex.framework.web.api.graphql2.annotation.TypeField;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module.Type;

@GraphQL2Module(type=Type.User,description = "商品品牌查询")
public class GoodsBrandGraphql {

	@Reference
	private GoodsService goodsService;

	@Autowired
	private StorageService storageService;
	
	@TypeField(type = GoodsBrand.class, field = "logo", description = "logo")
	public StorageInfo logo(@Source GoodsBrand source) {
		return storageService.get(source.getLogo());
	}

	@TypeField(type = GoodsBrand.class, field = "image", description = "图片")
	public StorageInfo image(@Source GoodsBrand source) {
		return storageService.get(source.getImage());
	}
	
	@TypeField(type = GoodsBrand.class, field = "goodsNumber", description = "品牌下的商品数量")
	public Long goodsNumber(@Source GoodsBrand source) {
		return goodsService.countDirectMailGoodsNumberByBrandId(source.getBrandId());
	}
	
	@QueryField(field = "goodsBrandList", description = "查询商品品牌列表")
	public Pagination<GoodsBrand> query(String name, @NonNull Page page) {
		return goodsService.queryBrandForH5(name, page);
	}
	
	@QueryField(field = "goodsBrand", description = "获取商品品牌详情")
	public GoodsBrand get(Integer brandId) {
		return goodsService.getBrandById(brandId);
	}
}
